package com.ruicar.afs.cloud.apply.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruicar.afs.cloud.common.core.entity.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author Lee
 * @date 2020/5/11 18:33
 * @description: GPS申请表
 */
@Data
@TableName(value = "apply_gps_info", autoResultMap = true)
@Accessors(chain = true)
public class ApplyGpsInfo extends BaseEntity<ApplyGpsInfo> {
    /**
     * 申请编号
     */
    private String applyNo;
    /**
     * 合同号码
     */
    private String contractNo;
    /**
     * 车辆编号
     */
    private String carId;
    /**
     * 车架号
     */
    private String carVin;
    /**
     * GPS供应商
     */
    private String gpsSupplier;
    /**
     * 是否盗抢包
     */
    private String isRobberyBag;
    /**
     * GPS产品编号
     */
    private String gpsProductNo;
    /**
     * 预安装时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date preInstallTime;
    /**
     * 贷款期限
     */
    private Integer loanTerm;
    /**
     * 现场联系人
     */
    private String siteContact;
    /**
     * 联系人电话
     */
    private String contactPhone;
    /**
     * 安装地址-省份
     */
    private String installProvince;
    /**
     * 安装地址-城市
     */
    private String installCity;
    /**
     * 安装地址-区县
     */
    private String installCounty;
    /**
     * 安装地址-街道
     */
    private String installStreet;
    /**
     * 安装地址-详细
     */
    private String installAddress;
    /**
     * 国标码
     */
    private String gbCode;
    /**
     * 户籍地址-省份
     */
    private String houseProvince;
    /**
     * 户籍地址-城市
     */
    private String houseCity;
    /**
     * 户籍地址-区县
     */
    private String houseCounty;
    /**
     * 户籍地址-街道
     */
    private String houseStreet;
    /**
     * 户籍地址-详细
     */
    private String houseAddress;
    /**
     * GPS申请状态
     */
    private String applyStatus;
    /**
     * 工单号
     */
    private String orderNo;
    /**
     * 备注
     */
    private String remarks;
    /**
     * gps型号
     */
    private String gpsType;
    /**
     * 回显页面翻译用  安装地址
     */
    @TableField(exist = false)
    private String[] installAddressTemp;
    /**
     * 回显页面翻译用  户籍地址
     */
    @TableField(exist = false)
    private String[] houseAddressTemp;

    public String[] getInstallAddressTemp() {
        if (StringUtils.isEmpty(this.installProvince)
                && StringUtils.isEmpty(this.installCity)
                && StringUtils.isEmpty(this.installCounty)
                && StringUtils.isEmpty(this.installStreet)) {
            return null;
        } else {
            return new String[]{this.installProvince, this.installCity, this.installCounty, this.installStreet};
        }
    }

    public String[] getHouseAddressTemp() {
        if (StringUtils.isEmpty(this.houseProvince)
                && StringUtils.isEmpty(this.houseCity)
                && StringUtils.isEmpty(this.houseCounty)
                && StringUtils.isEmpty(this.houseStreet)) {
            return null;
        } else {
            return new String[]{this.houseProvince, this.houseCity, this.houseCounty, this.houseStreet};
        }
    }

    public void setInstallAddressTemp(String[] installAddressTemp) {
        if (installAddressTemp != null) {
            if (installAddressTemp.length >= 1) {
                this.installProvince = installAddressTemp[0];
            }
            if (installAddressTemp.length >= 2) {
                this.installCity = installAddressTemp[1];
            }
            if (installAddressTemp.length >= 3) {
                this.installCounty = installAddressTemp[2];
            }
            if (installAddressTemp.length >= 4) {
                this.installStreet = installAddressTemp[3];
            }
            this.installAddressTemp = installAddressTemp;
        }
    }

    public void setHouseAddressTemp(String[] houseAddressTemp) {
        if (houseAddressTemp != null) {
            if (houseAddressTemp.length >= 1) {
                this.houseProvince = houseAddressTemp[0];
            }
            if (houseAddressTemp.length >= 2) {
                this.houseCity = houseAddressTemp[1];
            }
            if (houseAddressTemp.length >= 3) {
                this.houseCounty = houseAddressTemp[2];
            }
            if (houseAddressTemp.length >= 4) {
                this.houseStreet = houseAddressTemp[3];
            }
        }
        this.houseAddressTemp = houseAddressTemp;
    }

}
